﻿using System;
using System.Data;
using System.Web.UI.WebControls;
using BLL;
using Utils;
namespace UI.ModSalesman
{
    public partial class InList : System.Web.UI.Page
    {
        SalesmanBiz salesmanBiz = new SalesmanBiz();
        string saleManID = "0";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Params["SaleManID"] != null) saleManID = Request.Params["SaleManID"].ToString().Trim();          
            if (!IsPostBack)
            {
                btnAdd.Attributes.Add("onclick", "javascript:ShowLink('InAdd.aspx',800,550);");
                //JSUtility.AddReset(btnClear);
                if (saleManID != "0")
                {
                    DataTable dt = salesmanBiz.GetInLists(saleManID);
                    gvList.DataSource = dt;
                    gvList.DataBind();
                    lbAmount.Text = dt.Rows.Count.ToString();
                }
            }
        }
        protected void btnEmSearch_Click(object sender, EventArgs e)
        {
            string serWord = txtSerWord.Text.Trim();
            string deptName = txtDeptName.Text.Trim();
            string bTime = txtBtime.Text.Trim();
            string eTime = txtEtime.Text.Trim();
            string timeType = ddlTimeType.SelectedValue;
            if (deptName==""&&string.IsNullOrEmpty(serWord) && string.IsNullOrEmpty(bTime))
            {
                bTime = System.DateTime.Now.AddMonths(-2).ToString("yyyy-MM-dd");
                txtBtime.Text = bTime;
                txtEtime.Text = System.DateTime.Now.ToString("yyyy-MM-dd");
            }
            DataTable dt = salesmanBiz.GetInLists(serWord,deptName, bTime, eTime, timeType);
            gvList.DataSource = dt;
            gvList.DataBind();
            lbAmount.Text = dt.Rows.Count.ToString();

        }
        protected void btnExcel_Click(object sender, EventArgs e)
        {
            string serWord = txtSerWord.Text.Trim();
            string deptName = txtDeptName.Text.Trim();
            string bTime = txtBtime.Text.Trim();
            string eTime = txtEtime.Text.Trim();
            string timeType = ddlTimeType.SelectedValue;
            ExcelUtility.ExportDsToXls(this, salesmanBiz.GetInLists(serWord, deptName,bTime, eTime, timeType), "SalesLeave.xls");
            // ExcelUtility.GridViewToExcel(gvList, "SalesLeave.xls");
        }
        protected void gvList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
            {
                e.Row.Cells[0].Visible = false;
            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#F3F8F8'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
            }
        }
    }
}